function setCookie(name, value, seconds) {
    seconds = seconds || 0;   //seconds有值就直接赋值，没有为0    
    var expires = "";
    if (seconds != 0) {      //设置cookie生存时间    
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expires + "; path=/";   //转码并赋值    
}
function setInof(key, value) {
    localStorage.setItem(key, value);
    setCookie(key, value)//存储localStorage的同时，也存储一个cookie来监听
}
// To login
function reg() {
    event.returnValue = false;
    var name = document.getElementById("name").value;
    var password = document.getElementById("password").value;
    let data = {username:name,pwd:password}; 
    function ok(){
        console.log(this.responseText);
        if(this.responseText == "success"){
            setInof("Token", name);
            localStorage.setItem("UserName", name);
            location.replace('../index.html')
        }else{
            alert(this.responseText);
        }
        
    }
    function ko(){
        alert("Something wrong with login")
    }
    ajaxRequest("../php/login.php",'post',data,ok,ko);
    
}